﻿/*
 * Created by SharpDevelop.
 * User: IEscarro
 * Date: 8/25/2009
 * Time: 9:54 AM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Collections.Generic;

namespace Miming.Model
{
	/// <summary>
	/// Description of PurchaseOrder.
	/// </summary>
	public class PurchaseOrder
	{
		int id;
		Class _class;
		string pONo;
		string vendorDetails;
		
		public virtual string VendorDetails {
			get { return vendorDetails; }
			set { vendorDetails = value; }
		}
		string shipTo;
		
		public virtual string ShipTo {
			get { return shipTo; }
			set { shipTo = value; }
		}
		
		public virtual string PONo {
			get { return pONo; }
			set { pONo = value; }
		}
		string message;
		
		public virtual string Message {
			get { return message; }
			set { message = value; }
		}
		string memo;
		
		public virtual string Memo {
			get { return memo; }
			set { memo = value; }
		}
		
		public virtual Class Class {
			get { return _class; }
			set { _class = value; }
		}
		
		public virtual int Id {
			get { return id; }
			set { id = value; }
		}
		DateTime date = DateTime.Now;
		
		public virtual DateTime Date {
			get { return date; }
			set { date = value; }
		}
		Vendor vendor;
		
		public virtual Vendor Vendor {
			get { return vendor; }
			set { vendor = value; }
		}
		IList<PurchaseOrderItem> items = new List<PurchaseOrderItem>();
		
		public virtual IList<PurchaseOrderItem> Items {
			get { return items; }
			set { items = value; }
		}
		
		public PurchaseOrder()
		{
		}
		
		public virtual void AddItem(PurchaseOrderItem item)
		{
			item.Order = this;
			items.Insert(0, item);
			OnItemAdded(null);
		}
		
		protected virtual void OnItemAdded(EventArgs e)
		{
			if (ItemAdded != null) {
				ItemAdded(this, e);
			}
		}
		
		public virtual event EventHandler ItemAdded;
	}
	
	public class PurchaseOrderItem
	{
		int id;
		double rate;
		Customer customer;
		
		public virtual Customer Customer {
			get { return customer; }
			set { customer = value; }
		}
		UnitOfMeasure unitOfMeasure;
		
		public virtual UnitOfMeasure UnitOfMeasure {
			get { return unitOfMeasure; }
			set { unitOfMeasure = value; }
		}
		
		public virtual double Amount {
			get { return rate * quantity; }
		}
		
		public virtual double Rate {
			get { return rate; }
			set { rate = value; }
		}
		
		public virtual int Id {
			get { return id; }
			set { id = value; }
		}
		Item item;
		
		public virtual Item Item {
			get { return item; }
			set { item = value; Rate = item.Cost; }
		}
		PurchaseOrder order;
		
		public virtual PurchaseOrder Order {
			get { return order; }
			set { order = value; }
		}
		double quantity;
		
		public virtual double Quantity {
			get { return quantity; }
			set { quantity = value; }
		}
		
		public PurchaseOrderItem()
		{
		}
		
		public PurchaseOrderItem(Item item) : this(item, 1)
		{
		}
		
		public PurchaseOrderItem(Item item, double quantity)
		{
			this.Item = item;
			this.quantity = quantity;
		}
		
//		protected virtual void OnItemChanged(EventArgs e)
//		{
//			if (ItemChanged != null) {
//				ItemChanged(this, e);
//			}
//		}
//		
//		public virtual event EventHandler ItemChanged;
	}
}
